package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Form4_1;
 
 
public class Form4_1DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Form4_1DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Form4_1 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Form4_1> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Form4_1> list = session.selectList("Form4_1.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form4_1 instance from the database*/
    public Form4_1 selectById(int or_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form4_1 form4_1 = (Form4_1) session.selectOne("Form4_1.getById",or_no);
            return form4_1;
        } finally {
            session.close();
        }
    }
 
    /**Updates an instance of Form4_1 in the database*/
    public void update(Form4_1 form4_1){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form4_1.update", form4_1);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Insert an instance of Form4_1 into the database*/
    public void insert(Form4_1 form4_1){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Form4_1.insert", form4_1);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Form4_1 from the database*/
    public void delete(int or_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Form4_1.deleteById", or_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}